<?php
 
if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){
	$rtf = $GLOBALS["HTTP_RAW_POST_DATA"];
	$namedata = $_GET["name"];
	$arrName = explode("|",$namedata);
	$name = $arrName[1];
	$nameguid = $arrName[0];
	
	$dirname = '../djData/'.$nameguid;
	if(!file_exists($dirname))
		mkdir($dirname);
	$dirname .= '/savertf';
	if(!file_exists($dirname))
		mkdir($dirname);
	
	$save_to = $dirname."/". $name.".rtf";
	file_put_contents($save_to, $rtf);
 
	if(!file_exists($save_to)) 
		die("I'm sorry, the file doesn't seem to exist.");
	else{
		/*readfile($save_to);
		header("Content-Disposition: attachment; filename=\"$save_to\"");
		header("Content-Type: application/force-download");
		header("Content-Type: application/octet-stream");
		header("Content-Type: application/download");*/
		$file = $save_to;
		header('Content-Description: File Transfer');
		header('Content-Type: application/octet-stream');
		header('Content-Disposition: attachment; filename='.basename($file));
		header('Content-Transfer-Encoding: binary');
		header('Expires: 0');
		header('Cache-Control: must-revalidate');
		header('Pragma: public');
		header('Content-Length: ' . filesize($file));
		ob_clean();
		flush();
		readfile($file);
		exit;
	} 
} else{
	echo "Encoded RTF information not received.";
}
?>